﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VipSys.Common.Library;
using VipSys.DataLayer;
using VipSys.SystemEntity;

namespace VipSys
{
    public partial class SubPlaceMag : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDll();
            }
        }
        private void BindDll()
        { 
            Orgnization query=new Orgnization();
            query.RoleType=SystemData.RoleType.PROVINCE;
            List<Orgnization> lstOrgnization=new List<Orgnization>();
            short shRet = OrgnizationAccess.Instance.GetOrgnizationList(query, ref lstOrgnization);
            if (shRet != SystemData.ReturnValue.OK)
                return;
            this.ddlProvince.Items.Clear();
            foreach (var item in lstOrgnization)
            {
                this.ddlProvince.Items.Add(new ListItem(item.OrgName, item.ID.ToString()));
            }
            this.ddlProvince.Items.Insert(0, new ListItem("请选择", ""));
        }
        protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.ddlProvince.SelectedValue.ToString()))
                return;
            Orgnization query = new Orgnization();
            this.ddlCity.Items.Clear();
            query.ParentID = this.ddlProvince.SelectedValue.ToString();
            List<Orgnization> lstOrgnization = new List<Orgnization>();
            short shRet = OrgnizationAccess.Instance.GetOrgnizationList(query, ref lstOrgnization);
            if (shRet != SystemData.ReturnValue.OK)
                return;
            foreach (var item in lstOrgnization)
            {
                this.ddlCity.Items.Add(new ListItem(item.OrgName, item.ID.ToString()));
            }
            this.ddlCity.Items.Insert(0, new ListItem("请选择", ""));
        }
        protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.ddlCity.SelectedValue.ToString()))
                return;
            Orgnization query = new Orgnization();
            this.ddlSchool.Items.Clear();
            query.ParentID = this.ddlCity.SelectedValue.ToString();
            List<Orgnization> lstOrgnization = new List<Orgnization>();
            short shRet = OrgnizationAccess.Instance.GetOrgnizationList(query, ref lstOrgnization);
            if (shRet != SystemData.ReturnValue.OK)
                return;
            foreach (var item in lstOrgnization)
            {
                this.ddlSchool.Items.Add(new ListItem(item.OrgName, item.OrgName));
            }
            this.ddlSchool.Items.Insert(0, new ListItem("请选择", ""));
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            SysAccount sysAccount = Session["SysAccount"] as SysAccount;
            if(String.IsNullOrEmpty(this.ddlSchool.SelectedValue))
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('未选择考点，不能提交!')</script>");
                return;
            }
            User user = new User();
            user.ID=sysAccount.ID;
            UserAccess.Instance.GetUser(user, ref user);
            user.ExamSchool = this.ddlSchool.SelectedValue;
            short shRet=  UserAccess.Instance.Edit(user);
            if (shRet != SystemData.ReturnValue.OK)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('提交失败')</script>");
                return;
            }
            this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('提交成功，请等待机构为您分房！')</script>");
        }

    }
}